package edu.nanyang.dao;

import edu.nanyang.domain.MajorInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MajorInfoDao {
    @Insert("insert into major_info(major_name,academy_info_id,creator,create_time) values(#{majorName},#{academyInfoId},#{creator},now())")
    int add(MajorInfo majorInfo);

    //使用@Delete注解指明deleteById方法要执行的SQL
    @Delete("delete from major_info where id=#{id}")
    int delete(int id);

    //使用@Update注解指明update方法要执行的SQL
    @Update("update major_info set operate_time=now(),major_name=#{majorName},academy_info_id=#{academyInfoId} where id=#{id}")
    int update(MajorInfo majorInfo);

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "major_name",property = "majorName"),
            @Result(column = "academy_info_id",property = "academyInfoId"),
            @Result(column = "academy_info_id",property = "academyInfo",one = @One(select ="edu.nanyang.dao.AcademyInfoDao.getById"))
    })
    @Select("select * from major_info")
    List<MajorInfo> findAll();

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "major_name",property = "majorName"),
            @Result(column = "academy_info_id",property = "academyInfoId"),
            @Result(column = "academy_info_id",property = "academyInfo",one = @One(select ="edu.nanyang.dao.AcademyInfoDao.getById"))
    })
    @Select("select * from major_info where id=#{id}")
    MajorInfo getById(int id);

}
